package com.atguigu.jxc.service.impl;


import com.alibaba.fastjson.JSONArray;
import com.atguigu.jxc.dao.DamageListDao;
import com.atguigu.jxc.dao.DamageListGoodsDao;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.DamageListGoods;
import com.atguigu.jxc.service.DamageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DamageServiceImpl implements DamageService {

    @Autowired
    private DamageListDao damageListDao;
    @Autowired
    private DamageListGoodsDao damageListGoodsDao;

    @Override
    public void save(DamageList damageList, String damageListGoodsStr) {
        damageListDao.insert(damageList);
        List<DamageListGoods> damageListGoods = JSONArray.parseArray(damageListGoodsStr, DamageListGoods.class);
        for (DamageListGoods damageListGood : damageListGoods) {
            Integer damageListId = damageList.getDamageListId();
            damageListGood.setDamageListId(damageListId);
            damageListGoodsDao.insert(damageListGood);
        }
    }

    @Override
    public Map<String, Object> getdamageList(String sTime, String eTime) {
        HashMap<String, Object> map = new HashMap<>();
        List<DamageList> damageLists =  damageListDao.selectDamageLsit(sTime,eTime);
        map.put("rows",damageLists);
        return map;
    }

    @Override
    public Map<String, Object> getdamageGoodsList(Integer damageListId) {
        HashMap<String, Object> map = new HashMap<>();
        List<DamageListGoods> damageGoodsList =  damageListGoodsDao.selectDamageGoodsLsit(damageListId);
        map.put("rows",damageGoodsList);
        return map;
    }

}
